import doT from '../../../../../vendor/template/doT.js';
import watermark from '../../../../common/watermark.js';
import salesdailyApi from "../../../../common/api/bi/salesdaily.api.js"
import { DictionaryType, requestDict } from "../../../../common/dictionary/dictionary-type.js";
import WxcodeApi from '../../../../common/api/account/wxcode.api.js';

const template = doT.template($('#cust-day-template').text());
let _json = Utils.ParsingUrl(window.location);

(function (window, document, $) {
    new Vue({
        el: '#insidesales-app',
        data() {
            return {
                timer: null,
            }
        },
        mounted() {
            this.initialize();
            this.watermarkBgImg();
            this.initCommand();
        },
        methods: {
            //内容初始化
            async initialize() {
                //销售品类
                let _type = await requestDict(DictionaryType.LEVEL_TYPE);

                let cust = {
                    "bizDate": _json.bizDate,
                    "isInOrg": true
                }
                salesdailyApi.postSaleCust(cust).then(res => {
                    let newItems = []
                    res.forEach(item => {
                        item.entries.forEach(itm => {
                            itm.specLevel = _type.data.find(s => s.value == itm.specLevel).displayName;
                            //newItems.push({ ...itm });
                        });
                        newItems.push({ ...item });
                    });
                    $('#cust-content').empty().append(template({ list: newItems }));
                    $('#thisYear').text(moment().format('YYYY'));
                });
            },
            initCommand() {
                $(document).on('click', '#returnlist', function () {
                    //location.href = `../livestock/salesdaily.html`;
                    window.history.go(-1);
                });
            },
            //水印信息
            watermarkBgImg() {
                let _userInfo = JSON.parse(Utils.GetSessionStorage("SNAccountEply")) || JSON.parse(Utils.GetSessionStorage("SNLoginUserInfo"));
                //watermark.set(_userInfo.name || _userInfo.un);// 水印
                return WxcodeApi.queryUserInfo().then(res => {
                    watermark.set(res.name + res.numCode);// 水印
                }).catch(_ => {
                    watermark.set(_userInfo.un);// 水印
                });
            },
        }
    });

})(window, document, jQuery)